/*
 * @Author: your name
 * @Date: 2021-05-11 17:16:41
 * @LastEditTime: 2021-05-12 10:34:11
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \koa2-serve\dbHelper.js
 */
const mongoose = require("mongoose");
const { dbUrl } = require(".//config.js");

// 连接
mongoose.connect(dbUrl, {
  useNewUrlParser: true,
  useUnifiedTopology: true
});

// 连接成功
mongoose.connection.on("connected", function () {
    console.log("Mongoose connection open to ", dbUrl);
});

// 连接异常
mongoose.connection.on("error", function (err) {
    console.log("Mongoose connection error: " + err);
});

// 断开连接
mongoose.connection.on("disconnected", function () {
    console.log("Mongoose connection disconnected");
});

module.exports = mongoose